package com.lil.shiro.dao;

import com.lil.shiro.model.User;
import org.apache.ibatis.annotations.*;

import java.util.Set;

@Mapper
public interface UserMapper extends MyBaseMapper<User> {

    // 获取用户具体信息 【包含：角色 + 资源】
    @Select(" SELECT * FROM USER_INFO WHERE user_id = #{user_id} ")
    @Results(id = "userRoleResourceMap", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "create_date", property = "createDate"),
            @Result(column = "telphone", property = "telphone"),
            @Result(column = "update_date", property = "updateDate"),
            @Result(column = "token", property = "token"),
            @Result(property = "password", javaType = String.class, column = "user_id",
                    many = @Many(select = "com.lil.shiro.dao.PasswordMapper.getPasswordByUserId")
            ),
            @Result(property = "roles", javaType = Set.class, column = "user_id",
                    many = @Many(select = "com.lil.shiro.dao.RoleMapper.getRoleByUserId")
            )
    })
    User findUserInfo(String user_id);
}
